package com.esint.validation.entity.car;

import com.esint.validation.validators.CarUserAdd;
import com.esint.validation.validators.CarUserUpdate;
import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @description: 车主类
 * @author: 谷明
 * @createDate: 2021/8/12 19:27
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CarUser {
    @Null(message = "id不能赋值", groups = CarUserAdd.class)
    @NotBlank(message = "id不能为空", groups = CarUserUpdate.class)
    private String id;
    @NotBlank(message = "车主姓名不能为空")
    private String name;
    @Max(value = 1, message = "性别只能是1（男）或者0（女）")
    @Min(value = 0, message = "性别只能是1（男）或者0（女）")
    private Integer gender;
    @Range(min = 1, max = 80, message = "车主年龄需要在1-80岁之间")
    private Integer age;
    @Pattern(regexp = "^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$", message = "身份证号格式不正确")
    private String idNo;//身份证号
    @Past(message = "身份证有效期开始日期必须小于当前时间")
    private LocalDate idNoEffictiveStart;
    @Future(message = "身份证有效期截止日期必须大于当前时间")
    private LocalDate idNoEffictiveEnd;
    @Size(max = 50, min = 20, message = "车主地址需要在20~50字之间")
    private String address;

    //嵌套对象的校验
    @Valid
    private Car myCar;

    // 用来生成postman的数据
//    public static void main(String[] args) {
//        CarUser carUser = new CarUser(UUID.randomUUID().toString(), "小红", 0, 12, "410411198806073214", LocalDateTime.of(2016, 3,12, 0, 0),LocalDateTime.of(2016, 3,12, 0, 0), "鞍山西道");
//        String strJson = new Gson().toJson(carUser);
//        System.out.println(strJson);
//    }
}
